using System;
using System.Linq;
using NHibernate.Linq;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;

namespace Nvigorate.Repository.Test
{
    public class TestRegistry : Registry
    {
        public TestRegistry()
        {
            ForRequestedType<ISessionManager>().AddConcreteType<TestSessionManager>().CacheBy(InstanceScope.Singleton);
            ForRequestedType(typeof(IRepository<>)).TheDefaultIsConcreteType(typeof(Repository<>));
            
            
            ForRequestedType(typeof (FetchingStrategy<>.For<>)).TheDefaultIsConcreteType(
                typeof (DefaultFetchingStrategy<,>));
            
            ForRequestedType(typeof(FetchingStrategy<IMyOtherCarIsAMearas>.For<Person>)).TheDefaultIsConcreteType(
                typeof(MyOtherCarIsASteedFetchingStrategy));

            ForRequestedType(typeof(FetchingStrategy<IRegisterVehicle>.For<Person>)).TheDefaultIsConcreteType(
                typeof(RegisterVehicleFetchingStrategy));
        }
    }

    public class DefaultFetchingStrategy<T, TEntity> : FetchingStrategy<T>.For<TEntity>
    {
        public IQueryable<TEntity> ApplyTo(INHibernateQueryable<TEntity> queryable)
        {
            return queryable.Expand("");
        }
    }
}